/**
 * @author ZhiWen Ren
 * @version 1.0
 * @description: LeetCode-152-乘积最大的子数组
 * @date 2025/8/15 15:02
 */
public class Solution152 {
    public static int maxProduct(int[] nums) {
        int max = nums[0];
        int min = nums[0];
        int ans = nums[0];

        for (int i = 1; i < nums.length; i++) {
            int preMax = max;
            max = Math.max(nums[i], Math.max(preMax * nums[i], min * nums[i]));
            min = Math.min(nums[i], Math.min(preMax * nums[i], min * nums[i]));
            ans = Math.max(ans, max);
        }

        return ans;
    }

    public static void main(String[] args) {
        maxProduct(new int[]{-4, -3, -2});
    }
}
